using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration
{
    /// <summary>
    /// 应用设置管理器接口
    /// 提供对 appsettings.json 配置文件的统一访问和管理功能
    /// </summary>
    public interface IAppSettingsManager
    {
        /// <summary>
        /// 获取指定键的配置值
        /// </summary>
        /// <typeparam name="T">返回值类型</typeparam>
        /// <param name="key">配置键，支持层级键（如："Database:ConnectionString"）</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>配置值</returns>
    T GetValue<T>(string key, T defaultValue = default!);

        /// <summary>
        /// 获取指定键的字符串配置值
        /// </summary>
        /// <param name="key">配置键</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>配置值</returns>
        string GetStringValue(string key, string? defaultValue = null);

        /// <summary>
        /// 获取指定键的整数配置值
        /// </summary>
        /// <param name="key">配置键</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>配置值</returns>
        int GetIntValue(string key, int defaultValue = 0);

        /// <summary>
        /// 获取指定键的布尔配置值
        /// </summary>
        /// <param name="key">配置键</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>配置值</returns>
        bool GetBoolValue(string key, bool defaultValue = false);

        /// <summary>
        /// 获取指定配置节的所有子配置
        /// </summary>
        /// <param name="sectionKey">配置节键</param>
        /// <returns>配置字典</returns>
    IDictionary<string, string> GetSection(string sectionKey);

        /// <summary>
        /// 绑定配置节到指定的对象类型
        /// </summary>
        /// <typeparam name="T">目标对象类型</typeparam>
        /// <param name="sectionKey">配置节键</param>
        /// <returns>绑定后的对象实例</returns>
        T GetSection<T>(string sectionKey) where T : class, new();

        /// <summary>
        /// 获取数据库连接字符串
        /// </summary>
        /// <param name="name">连接字符串名称</param>
        /// <returns>连接字符串</returns>
        string GetConnectionString(string name);

        /// <summary>
        /// 检查指定配置键是否存在
        /// </summary>
        /// <param name="key">配置键</param>
        /// <returns>是否存在</returns>
        bool HasKey(string key);

        /// <summary>
        /// 获取所有配置键值对
        /// </summary>
        /// <returns>配置键值对字典</returns>
    IDictionary<string, string> GetAllSettings();

        /// <summary>
        /// 重新加载配置
        /// </summary>
        void Reload();

        /// <summary>
        /// 获取配置变更通知
        /// </summary>
        /// <param name="callback">配置变更回调</param>
        /// <returns>变更令牌</returns>
    IDisposable? OnChange(Action callback);
    }
}
